#include "nemu.h"

int init_monitor(int, char *[]);
void ui_mainloop(int);
uint32_t expr(char *e, bool *success);
uint8_t str2uint(char* str , uint32_t* res ,uint8_t code);

int compare_res() {
  char strbuf[4096];//1024*4
  uint32_t num;
  FILE *fp = fopen("/tmp/.input", "r");
  bool suc;

  assert(fp != NULL);
  while(fgets(strbuf,4096,fp)!= NULL) {
      char* nums =strtok(strbuf, " ");
      char* exprs =strtok(NULL, " ");
      exprs[strlen(exprs)-1]='\0';
      uint32_t res = expr(exprs,&suc);
      if(suc) {
        str2uint(nums,&num,10);
        if (num != res) 
          printf("ERRO : %s %d res=%d \n",exprs,num,res);
        else
          printf("INFO : %s %d res=%d \n",exprs,num,res);
      } else 
          printf("ERRO : illegal expres %s \n",exprs);
  }
  fclose(fp);
  return 0;
}

int main(int argc, char *argv[]) {
  /* Initialize the monitor. */
  int is_batch_mode = init_monitor(argc, argv);
  // compare_res();
  /* Receive commands from user. */
  ui_mainloop(is_batch_mode);

  return 0;
}
